package cn.pconline.autoclub.util.dyna;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 *
 * @author <a href="mailto:chensy0203@163.com">chensy</a>
 */
public class AbstractDyna {

    protected long clubId;
    protected long targetId;
    protected String content;
    protected long createBy;
    protected Date createDate;  //创建时间
    protected String createName;//创建者名称
    protected int fromType;	//动态来源

    public long getClubId() {
        return clubId;
    }

    public void setClubId(long clubId) {
        this.clubId = clubId;
    }

    public long getTargetId() {
        return targetId;
    }

    public void setTargetId(long targetId) {
        this.targetId = targetId;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(long createBy) {
        this.createBy = createBy;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getCreateName() {
        return createName;
    }

    public void setCreateName(String createName) {
        this.createName = createName;
    }
    
    public int getFromType() {
		return fromType;
	}

	public void setFromType(int fromType) {
		this.fromType = fromType;
	}



	/**
     * 动态排序项
     *
     * @author user
     *
     */
    public static enum DynaOrder {

        PRAISE_COUNT_DESC("点赞降序"), POST_COUNT_DESC("回复数降序"), //降序
        PRAISE_COUNT("点赞升序"), POST_COUNT("回复数升序"); //升序
        private String name;

        DynaOrder(String name) {
            this.name = name;
        }
        private final static Map<Integer, DynaOrder> orders = new HashMap<Integer, DynaOrder>();

        static {
            for (DynaOrder item : DynaOrder.values()) {
                orders.put(item.getId(), item);
            }
        }

        public static Set<Integer> listOrderItemIdx() {
            return orders.keySet();
        }

        public static DynaOrder[] listOrderItem() {
            return DynaOrder.values();
        }

        public static DynaOrder getReverseItem(int idx) {
            int len = values().length;
            int half = len / 2;
            int otherIdx;
            if (idx >= half) {
                otherIdx = idx % half;
            } else {
                otherIdx = idx + half;
            }
            return orders.get(otherIdx);
        }

        public static DynaOrder getOrderItem(int idx) {
            return orders.get(idx);
        }

        public int getId() {
            return this.ordinal();
        }

        public String getName() {
            return this.name;
        }

        public String getDesc(int idx) {
            int len = values().length;
            int half = len / 2;
            if (idx >= half) {
                return "asc";
            } else {
                return "desc";
            }
        }
    }
}
